package com.gitee.wsl.unit.angle.ext

import com.gitee.wsl.text.format.format
import com.gitee.wsl.unit.angle.AngleUnit

/**
 * Forms a decimal degrees [String] representation of this [Angle].
 *
 * @param digits the number of digits past the decimal point to include in the string.
 *
 * @return the value of this angle in decimal degrees as a string with the specified number of digits beyond the
 * decimal point. The string is padded with trailing zeros to fill the number of post-decimal point
 * positions requested.
 */
fun AngleUnit.toDDString(digits: Int = 6): String {
    require(digits in 0..15) {
        //logMessage(ERROR, "Angle", "toDecimalDegreesString", "outOfRange")
    }
    return String.format("%.${digits}f°",degrees)
}

/**
 * Obtains a [String] representation of this [Angle] formatted as degrees and decimal minutes.
 *
 * @param digits the number of digits past the decimal point to include in the string.
 *
 * @return the value of this angle in degrees and decimal minutes as a string.
 */
fun AngleUnit.toDMString(digits: Int = 3): String {
    val dms = toDMS()
    val mf = if (dms[3] == 0.0) dms[2] else dms[2] + dms[3] / 60.0
    return String.format("${if (dms[0] < 0) "-" else ""}%d° %2.${digits}f’",dms[1], mf)
}

val AngleUnit.arrow: String
    get() = when(sanitize360().degrees) {
        -1.0 -> "⟳"
        in 22.5..67.5 -> "↙"
        in 67.5..112.5 -> "←"
        in 112.5..157.5 -> "↖"
        in 157.5..202.5 -> "↑"
        in 202.5..247.5 -> "↗"
        in 247.5..292.5 -> "→"
        in 292.5..337.5 -> "↘"
        else -> "↓"
    }

